<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title><spring:message code="create_fashion_style"/></title>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
	<link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
	<link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
	<script src="${ctxStatic}/layDate/laydate.js"></script>
	<script type="text/javascript">
        $(document).ready(function() {
            $("#loading").hide();
            var buttonName = '${buttonName}';
            if (buttonName=="inOutImport") {
            	$("form")[0].action="${ctx}/material/stock/inoutImportData";
			}
        });
        /*保存方法*/
        function importExcel(t){
            ShowDiv();
            $(t).attr("disabled",true);
            var action=$("#inputForm").attr("action");
            var form = document.getElementById('inputForm');
            var fd = new FormData(form);
            var file=$("#uploadFile");
            if($(file).val()==''){
                alertInfo("<spring:message code='importExcel_error_msg'/>");
                $(t).attr("disabled",false);
                HiddenDiv();
                return false;
            }
            fd.append("file", file);
            var xhr = new XMLHttpRequest();
            if (xhr.upload) {
                // 文件上传成功或是失败
                xhr.onreadystatechange = function(e) {
                    if (xhr.readyState == 4) {
                        var result=JSON.parse(xhr.responseText);
                        if (xhr.status == 200) {
                            // 返回状态
                            HiddenDiv();
                            window.parent.frames[0].searchListForm();
                            if (result == "true") {
                                alert('<spring:message code="this_excel_ok"/>');
                                    closeWin();
                            } else {
                            	alert(result.message);
                                closeWin();
                            }
                            xhr=null;
                        }
                    }
                };
                // 开始上传
                xhr.open("POST", action, true);
                xhr.setRequestHeader("X_FILENAME", file.name);
                xhr.send(fd);
            }

            return false;
        }
        //显示加载数据
        function ShowDiv() {
            $("#loading").show();
        }

        //隐藏加载数据
        function HiddenDiv() {
            $("#loading").hide();
        }
    </script>
</head>
<body>
<form id="inputForm" action="${ctx}/material/stock/insertExcelData" method="post" onsubmit="formSubmit(this.action)" enctype="multipart/form-data">
<div class="tabBoxSm">
     <div class="tabSm smOrderBox" style="width:500px">
        <div class="items clearfix">
            <div class="col-50 clearfix">
                    <!-- 样板文件上传画面 -->
                     <strong style="font-size:15px;">
	                     <c:if test="${buttonName=='inOutImport' }">
	                     	<spring:message code="material_inoutboundImport"/>
	                     </c:if>
	                     <c:if test="${buttonName!='inOutImport' }">
	                     	<spring:message code="material_materialImport"/>
	                     </c:if>
                     </strong>
            </div>
            <div class="col-50 clearfix" >
            <div style="float:right;">
               <!-- 关闭 -->
               <button type="button" class="btn-js" onclick="closeWin()"><spring:message code="btn_cancle"/></button>
               </div>
            </div>
            <br><hr></hr>
        </div>
        <div class="items clearfix">
            <img id = "img" />
           <input type="file" name="file" style="width: 350px" data-rule-required="true" data-msg-required="<spring:message code="please_select_excel_file"/>">
           <button type="button" class="btn-js" onclick="importExcel(this)" style="height:34px"><spring:message code="pecimenProduct_btn_submit"/></button>
        </div>
         <div id="fileName">
         </div>
         <div id="fileSize">
         </div>
         <div id="fileType">
         </div>
         <div class="items clearfix">
             <div id="loading">
                 <img src="${ctxStatic}/images/loading.gif" alt="" style="width: 30px;height:30px"/>
                 <strong><font color="#6600ff"><spring:message code="excel_upload_waiting"/></font></strong>
             </div>
         </div>
         <div class="items clearfix">
             <strong><font color="#FF0000"><spring:message code="warning_excel_massage"/></font></strong>
         </div>
     </div>
</div>
</form>
</body>
</html>
